package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.ext.LoginUser;
import com.jiantong.work.impl.manager.ButcherAdmissionInspectionManager;
import com.jiantong.work.model.ButcherAdmissionInspection;
import com.jiantong.work.service.ButcherAdmissionInspectionWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by niufei on 2017/3/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class ButcherAdmissionInspectionWriteServiceImpl implements ButcherAdmissionInspectionWriteService{

    private final ButcherAdmissionInspectionManager butcherAdmissionInspectionManager;

    @Autowired
    public ButcherAdmissionInspectionWriteServiceImpl(ButcherAdmissionInspectionManager butcherAdmissionInspectionManager) {
        this.butcherAdmissionInspectionManager = butcherAdmissionInspectionManager;
    }


    @Override
    public Response<Map<String , Object>> create(ButcherAdmissionInspection butcherAdmissionInspection, Integer toStatus, LoginUser loginUser) {
        try{
            return Response.ok(butcherAdmissionInspectionManager.createButcherAdmissionInspection(butcherAdmissionInspection,toStatus,loginUser));
        }catch (Exception e){
            log.error("failed to create butcherAdmissionInspection error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("butcherAdmissionInspection.create.failed");
        }
    }

    @Override
    public Response< Map<String , Object>> update(ButcherAdmissionInspection butcherAdmissionInspection, Integer toStatus,LoginUser loginUser) {
        try{
            return Response.ok(butcherAdmissionInspectionManager.updateButcherAdmissionInspection(butcherAdmissionInspection,toStatus,loginUser));
        }catch (Exception e){
            log.error("failed to update butcherAdmissionInspection error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("butcherAdmissionInspection.update.failed");
        }
    }
}
